package me.monster.smarttraffic.bo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import me.monster.smarttraffic.tool.StringUtil;

public class DataHolder {

    private boolean login;
    private String account;
    private String quote;
    private String avatar;
    private String ipAddress;
    private String token;
    private int launchCount;
    private List<String> videoPathList = new ArrayList<>();
    private boolean videoDone;

    private DataHolder() {
    }

    public static DataHolder getInstance() {
        return SingletonInstance.INSTANCE;
    }

    public boolean isLogin() {
        return login;
    }

    public String getAccount() {
        return account == null ? "" : account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getQuote() {
        return quote == null ? "" : quote;
    }

    public void setQuote(String quote) {
        this.quote = quote;
    }

    public String getIpAddress() {
        return ipAddress == null ? "" : ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getToken() {
        return token == null ? "" : token;
    }

    public void setToken(String token) {
        this.token = token;
        login = StringUtil.isNotEmpty(token);
    }

    public int getLaunchCount() {
        return launchCount;
    }

    public void setLaunchCount(int launchCount) {
        this.launchCount = launchCount;
    }

    public String getAvatar() {
        return avatar == null ? "" : avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getVideoPath() {
        if (videoPathList.isEmpty()) {
            return "";
        }
        return videoPathList.get(0);
    }

    public void setVideoFileArray(File[] videoFileArray) {
        for (File file : videoFileArray) {
            videoPathList.add(file.getPath());
        }
        if (getVideoPath().endsWith("sampleVideo.mp4")) {
            setVideoDone(true);
        }
    }

    public boolean isVideoDone() {
        return videoDone;
    }

    public void setVideoDone(boolean videoDone) {
        this.videoDone = videoDone;
    }

    private static class SingletonInstance {
        private static final DataHolder INSTANCE = new DataHolder();
    }
}